﻿using System;
using System.Collections.Generic;
using System.Text;
using TCCHWLib.Commands;
using TCCHWLib;

namespace TCCSWLib
{
    public class JobScheduler
    {
        private static JobScheduler m_JobScheduler;
        private int m_CurrentProcessorIndex = 0;

        public static JobScheduler Instance
        {
            get {
                if (m_JobScheduler == null)
                    m_JobScheduler = new JobScheduler();

                return JobScheduler.m_JobScheduler;
            }
            set { JobScheduler.m_JobScheduler = value; }
        }

        private JobScheduler()
        {
        }

        public void AddJob(BatchCommand batch, PriorityKey priority)
        {
            batch.Priority = priority;

            Chip.Instance.Processors[m_CurrentProcessorIndex++].EnqueueTask(batch);

            if (m_CurrentProcessorIndex >= Chip.Instance.Processors.Count)
                m_CurrentProcessorIndex = 0;
        }
        public void AddIntialData(BatchCommand batch)
        {
            batch.ExecuteGlobal(Chip.Instance.Processors[0]);
        }
        public void FinalizeJob()
        {
            for (int i = 0; i < Chip.Instance.Processors.Count; i++)
            {
                Chip.Instance.Processors[i].EnqueueTask(null);
            }
        }
    }
}
